# @Time : 2020/6/28 17:24
# @Author : Fioman 
# @Phone : 13149920693
"""
如果定义的函数接收可变参数,应该谨慎考虑调用方是否期望修改传入的参数.
例如:如果函数接收一个字典,而且在处理的过程中要修改它,那么这个副作用要不要体现在函数的外部?
"""

class TwilightBus(object):
    """让乘客销声匿迹的校车"""
    def __init__(self,passengers = None):
        if passengers is None:
            self.passengers = []
        else:
            self.passengers = passengers


    def pick(self,name):
        self.passengers.append(name)

    def drop(self,name):
        self.passengers.remove(name)

    # __init__复制语句把self.passengers 变成passengers的别名,而它是传给函数的实参.
    # append和remove实际上会修改传给构造方法的那个列表.



if __name__ == '__main__':
    basketball_team = ['Sue', 'Tina', 'Maya', 'Diana', 'Pat']
    bus = TwilightBus(basketball_team)
    bus.drop("Tina")
    bus.drop("Pat")
    print("basketball_team = {}".format(basketball_team)) # 这里的有两个元素被drop掉了.不符合设计原则.
